﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace Corina.Converters.Silverlight
{
    public class SmallerThanToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            object parameterValue = System.Convert.ChangeType(parameter, value.GetType(), culture);
            bool visible = ((IComparable)value).CompareTo(parameterValue) < 0;
            return visible ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            Visibility visibility = (Visibility)value;
            return (visibility == Visibility.Visible);
        }
    }
}
